import java.util.LinkedList;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 666
 * Date: 2023-03-23
 * Time: 12:53
 */
public class test1 {
    public static void main(String[] args) {
        Scanner q=new Scanner(System.in);
        while (q.hasNext()) {
            int flag = 0;
            LinkedList<Object> arr = new LinkedList<>();

            int m = q.nextInt();
            int n = q.nextInt();
            if (m == 0) {
                System.out.println(0);
            }
            if (m < 0) {
                m = -m;
                flag = 1;
            }
            while (m > 0) {
                if (n < 10) {
                    int a = m % n;
                    m /= n;
                    arr.addFirst(a);
                } else if (n > 10) {
                    int a = m % n;
                    if (a == 10) {
                        arr.addFirst("A");
                    } else if (a == 11) {
                        arr.addFirst("B");
                    } else if (a == 12) {
                        arr.addFirst("C");
                    } else if (a == 13) {
                        arr.addFirst("D");
                    } else if (a == 14) {
                        arr.addFirst("E");
                    } else if (a == 15) {
                        arr.addFirst("F");
                    } else {
                        arr.addFirst(a);
                    }
                } else {
                    System.out.println(m);
                    return;
                }

            }
            if (flag == 1) {
                System.out.println("-");
            }
            for (int i = 0; i < arr.size(); i++) {
                System.out.print(arr.get(i));
            }
        }
    }
}
